﻿/*
*  系统设置HOME
*/

var baseModel = angular.module("baseModel", ['monospaced.qrcode','angularFileUpload', 'Common', 'loadModule', 'FileSelect', 'managerS'])


//基本信息设设置
baseModel.controller("baseSetController", ['$scope', '$rootScope', 'sysUserInfo',"FileUploader", "sysmanagerservice", 'Msg', '$http', "T", function ($scope, $rootScope, sysUserInfo, FileUploader,CS, Msg, $http, T) {

    //选择城市
    $scope.error = {};
    //基本信息设置
    $scope.list = [];
     $scope.list2 = [];
     $scope.error2 = {};

    /*****************************************************提现信息**********************************************************/
    $scope.showForm = false; //隐藏提现弹框
    //提现的参数
    $scope.item = {
        yue: 0,
        account: "", //提现账户
        phone: "", //联系方式
        money: 0, //提现金额
        Remarks: "", //备注
        userid: sysUserInfo.getuserinfo().user_ID,
        orgid: sysUserInfo.getuserinfo().organization_ID
    };
    //提现的方法
    $scope.saveObj = function () {
        //提交申请
        CS.saveOrgWithdrawals($scope.item).then(function (response) {
            if (response.errorcode == "0") {
                Msg.success("申请提交成功！");
                //关闭窗口
                $scope.openOrClose();
                //初始提现参数
                $scope.item.money = 0;
                $scope.item.account = "";
            }else if (response.errorcode == "58") {
                Msg.warning("您还有处理中的提现申请，暂时不能提现！");
            } else if (response.errorcode == "0") {
                Msg.success("权限不足！");
            } else {
                Msg.error("错误", "提现申请提交失败！");
            }
        });

    }
    //打开或关闭提现
    $scope.openOrClose = function () {
        $scope.item.yue = $scope.orginfo.organizationBalance ? $scope.orginfo.organizationBalance : 0;
        $scope.showForm = !$scope.showForm;
    }

    /*****************************************************企业信息**********************************************************/
    //初始企业参数
    $scope.orginfo2 = {
        organization_ID: sysUserInfo.getuserinfo().organization_ID,
        organization_Name: sysUserInfo.getuserinfo().organization_Name,
        province: "",
        city: "",
        area: "",
        industry: "",
        trade: "",
        address: "",
        synopsis: "",
        isOpenkf: false, //默认关闭
        organization_preview_set: false, //预览设置，默认关闭-先登录，后预览
        orgTels: "",
        organization_domain_name: "",
        organization_two_domain_name: "",
        WeChatQR:"",//企业二维码地址
        registerType: 1, //1企业还是2培训机构
        distributionRole: 1//分销角色 1.企业内部 2.平台直销
    }
    //获取  当前企业基本信息
    $scope.findOrgInfo = function () {
            //在拿一遍
            CS.findOrgInfo({ orgId: sysUserInfo.getuserinfo().organization_ID }).then(function (response) {
                if (response.errorcode == "0" && response.data != null && response.data != undefined) {// 成功       
                    $scope.orginfo = response.data;
                    //赋给默认值
                    if ($scope.orginfo.registerType == undefined) {
                        $scope.orginfo.registerType = 1;
                    }
                    if ($scope.orginfo.distributionRole == undefined) {
                        $scope.orginfo.distributionRole = 1;
                    }
                    if ($scope.orginfo.WeChatQR == undefined) {
                        $scope.orginfo.WeChatQR = "";
                    }
                    sysUserInfo.setorganizationinfo($scope.orginfo); //修改缓存
                    $http.get('/api/test/city.json').success(function (data) {
                        $scope.list = data;
                        $http.get('/api/test/industry.json').success(function (data2) {
                            $scope.list2 = data2;
                            $scope.forList();
                        });
                    });
                } else if (response.errorcode == "0" && (response.data == null || response.data == undefined)) {
                    $scope.orginfo = $scope.orginfo2;
                } else {   // 获取失败 
                    Msg.error("获取失败！");
                }
            }, function errorCallback() {
                console.log("连接服务器失败！");
            });
    }
    //修改企业基本信息
    $scope.saveOrgInfo = function () {
        RS.updateOrgInfo($scope.orginfo).then(function (response) {
            if (response.errorcode == "0") {// 成功       
                Msg.success("修改成功");
                sysUserInfo.setorganizationinfo($scope.orginfo); //修改缓存
            } else {   // 获取失败 
                Msg.error("获取失败！");
            }
        }, function errorCallback() {
            console.log("连接服务器失败！");
            $scope.isOK = true;
        });
    }
    //遍历企业的所在地
    $scope.forList = function () {
        if ($scope.orginfo.province != null && $scope.orginfo.province != "" && $scope.orginfo.province != undefined) {
            //遍历省
            $scope.coming_s = true;
            if ($scope.coming_s) {
                angular.forEach($scope.list, function (data) {
                    if ($scope.orginfo.province == data.name) {
                        $scope.province = data;
                        $scope.coming_s = false;
                    }
                });
            }
        }
        if ($scope.orginfo.city != null && $scope.orginfo.city != "" && $scope.orginfo.city != undefined && $scope.province != undefined) {
            //遍历城
            $scope.coming_c = true;
            if ($scope.coming_c) {
                angular.forEach($scope.province.child, function (data) {
                    if ($scope.orginfo.city == data.name) {
                        $scope.city = data;
                        $scope.coming_c = false;
                    }
                });
            }
        }
        if ($scope.orginfo.city != null && $scope.orginfo.city != "" && $scope.orginfo.city != undefined && $scope.province != undefined) {
            //遍历区
            $scope.coming_q = true;
            if ($scope.coming_q) {
                angular.forEach($scope.city.child, function (data) {
                    if ($scope.orginfo.area == data.value) {
                        $scope.area = data;
                        $scope.coming_q = false;
                    }
                });
            }
        }
        if ($scope.orginfo.industry != null && $scope.orginfo.industry != "" && $scope.orginfo.industry != undefined) {
            //遍历行业
            $scope.coming_hx = true;
            if ($scope.coming_hx) {
                angular.forEach($scope.list2, function (data) {
                    if ($scope.orginfo.industry == data.name) {
                        //console.log(data.name);
                        $scope.industry = data;
                        $scope.coming_hx = false;
                    }
                });
            }
        }
        if ($scope.orginfo.trade != null && $scope.orginfo.trade != "" && $scope.orginfo.trade != undefined && $scope.industry != undefined) {
            //遍历行业后
            $scope.coming_hx2 = true;
            if ($scope.coming_hx2) {
                angular.forEach($scope.industry.child, function (data) {
                    if ($scope.orginfo.trade == data.value) {
                        $scope.trade = data;
                        $scope.coming_hx2 = false;
                    }
                });
            }
        }
    }
    //第一个框选中事件
    $scope.c = function (c) {
        $scope.error.province = false;
        $scope.error.city = false;
        $scope.error.area = false;
        $scope.orginfo.province = c;
        $scope.city = "";
        $scope.area = "";
    };
    //第二个框选中事件
    $scope.c2 = function (c) {
        $scope.error.city = false;
        $scope.error.area = false;
        $scope.orginfo.city = c;
        $scope.area = "";
    };
    //第三个框选中事件
    $scope.c3 = function (c) {
        $scope.error.area = false;
        $scope.orginfo.area = c;
    };

    //第一个框选中事件
    $scope.c_hx = function (c) {
        $scope.error2.before = false;
        $scope.error2.after = false;
        $scope.orginfo.industry = c;
        $scope.trade = "";
    };
    //第二个框选中事件
    $scope.c_hx2 = function (c) {
        //         $scope.error.before = false;
        $scope.error2.after = false;
        $scope.orginfo.trade = c;
    };
    $scope.findOrgInfo(); //获取数据


     /*********************************************文件上传开始**********************************************/

     $scope.selectFile = function (index) {                
        $("#file").click();
    }

    var trainupfile = $scope.uploader = new FileUploader();
    trainupfile.onAfterAddingFile = function (fileItem) {  // 选择文件后 （成功）   0          
        console.info('onAfterAddingFile', fileItem);
        if (trainupfile.isUploading) {
            Msg.warning("有文件正在上传。。");
            return;
        } else {
            var upfileparam = "?userid=" + sysUserInfo.getuserinfo().user_ID + "&state=13";

            fileItem.url = RS.uploadCover(upfileparam);
        }
    };
    trainupfile.onAfterAddingAll = function (addedFileItems) { // 选择文件后添加到队列   1 
        console.info('onAfterAddingAll', addedFileItems);
        if (trainupfile.isUploading) {
            Msg.warning("有文件正在上传。。");
            return;
        } else { 
            trainupfile.uploadAll();
        }
    };
    trainupfile.onErrorItem = function (fileItem, response, status, headers) {     // 5上传失败
        console.info('onErrorItem', fileItem, response, status, headers);
    };
    trainupfile.onCompleteItem = function (fileItem, response, status, headers) {  //6     单文件上传完成
        console.info('onCompleteItem', fileItem, response, status, headers);
        if (response.errorcode == "0") {
            $scope.orginfo.WeChatQR=response.errormsg;
            $scope.saveOrgInfo();
        } else {
            Msg.error("图片上传异常！")
        }
    };
    trainupfile.onCompleteAll = function () {  // 6 单文件上传完成或者队列上传完成的时候
        console.info('onCompleteAll');
        //trainupfile.clearQueue();  // 上传完毕清除队列
    };
    /*********************************************文件上传结束**********************************************/


} ]);
/*****************************************************************功能设置********************************************************************************/
//功能设置
baseModel.controller("examSetController", ['$scope', 'sysUserInfo', '$stateParams', '$state', 'Msg', '$rootScope', "sysmanagerservice", "T", function ($scope, sysUserInfo, $stateParams, $state,Msg,$rootScope, RS,T) {
    
     // 请求参数 查询
    $scope.params = {
        orgid: sysUserInfo.getuserinfo().organization_ID,
        groupname:$rootScope.groupName,
        pageIndex:1,
        pageSize:100,
    };
    // 查询企业开关信息
    $scope.getCommonSet = function () {
        RS.findOrgSwitch($scope.params).then(function (response) {
            if (response.errorcode == "0") {
                $scope.commonlist=response.datas;
            } else if (response.errorcode == "40") {
                console.log("没有任何配置信息");
            } else {
                Msg.error("服务器异常");
            }
        });
    }
    $scope.getCommonSet();
    //打开或关闭开关
    $scope.updateState=function(item){
        RS.addOneSwitch({orgid:sysUserInfo.getuserinfo().organization_ID,orgname:sysUserInfo.getuserinfo().organization_Name,userid:sysUserInfo.getuserinfo().user_ID,username:sysUserInfo.getuserinfo().organization_Name,switchKey:item.switch_id}).then(function (response) {
                if (response.errorcode == "0") {
                    if(item.switchOrganization==undefined||item.switchOrganization==null||item.switchOrganization.is_switch!="0"){
                        item.switchOrganization={is_switch:"0"};
                    }else{
                        item.switchOrganization=null;
                    }
                    Msg.success("修改成功！");
                } else if (response.errorcode == "40") {
                    console.log("没有任何配置信息");
                } else {
                    Msg.error("错误！");
                }
            });
    }
} ]);
/*****************************************************************考试功能设置********************************************************************************/
//考试设置
baseModel.controller("ExamSetAndZBController", ['$scope', 'sysUserInfo', '$stateParams', '$state', 'Msg', '$rootScope', "sysmanagerservice", "T", function ($scope, sysUserInfo, $stateParams, $state,Msg,$rootScope, RS,T) {
    $scope.loading=false;
    $scope.commonlist=[];
     // 请求参数 查询
    $scope.params = {
        orgid: sysUserInfo.getuserinfo().organization_ID,
        groupname:$rootScope.groupName,
        pageIndex:1,
        pageSize:100,
    };
    // 查询企业开关信息
    $scope.getCommonSet = function () {
        RS.findOrgSwitch($scope.params).then(function (response) {
            if (response.errorcode == "0") {
                $scope.commonlist=response.datas;
            } else if (response.errorcode == "40") {
                console.log("没有任何配置信息");
            } else {
                Msg.error("服务器异常");
            }
        });
    }
    $scope.getCommonSet();
    //打开或关闭开关
    $scope.updateState=function(item){
        RS.addOneSwitch({orgid:sysUserInfo.getuserinfo().organization_ID,orgname:sysUserInfo.getuserinfo().organization_Name,userid:sysUserInfo.getuserinfo().user_ID,username:sysUserInfo.getuserinfo().organization_Name,switchKey:item.switch_id}).then(function (response) {
                if (response.errorcode == "0") {
                    if(item.switchOrganization==undefined||item.switchOrganization==null||item.switchOrganization.is_switch!="0"){
                        item.switchOrganization={is_switch:"0"};
                    }else{
                        item.switchOrganization=null;
                    }
                    Msg.success("修改成功！");
                } else if (response.errorcode == "40") {
                    console.log("没有任何配置信息");
                } else {
                    Msg.error("错误！");
                }
            });
    }
    //作弊设置的json
    $scope.fzbJson={
        similarityDegree:80,
	    cheatSwitch: true,
	    faceRecognitionSwitch: true,
	     cameraPlan:{id:1,title:"学员无摄像头？",btnList:[{id:"1",name:"踢出",isSel:false},{id:"2",name:"继续考试",isSel:false},{id:"3",name:"提示：",ts:"请输入提示语",value:"",isSel:false}]},
         shotPlan:{id:2,title:"抓拍方案？",btnList:[{id:"1",name:"学习开始",isSel:false},{id:"2",name:"考试开始",isSel:false},{id:"3",name:"考试结束",isSel:false},{id:"4",name:"定时抓拍",ts:"分钟",value:"",isSel:false}]},
	    originalPhoto: {id: 3,title: "学员无原始照片（学员在个人中心上传）？",btnList: [{id: "1",name: "踢出",isSel: false}, {id: "2",name: "继续考试",isSel: false}, {id: "3",name: "提示：",ts: "请输入提示语",isSel: true}]},
	    nonSelf: {id: 4,title: "原始照片比对拍照非本人时？",btnList: [{id: "1",name: "踢出",isSel: false}, {id: "2",name: "继续考试",isSel: false}, {id: "3",name: "提示：",ts: "请输入提示语",value: "非本人操作",isSel: true}]}
    }
    //多选
    $scope.checkSel=function(item){
        item.isSel=!item.isSel;
    }
    //单选
    $scope.checkDanSel=function(id,item){
        //取消其他选择
        if(!item.isSel){
            if(id==1){
                $scope.fzbJson.cameraPlan.btnList.forEach(function(data,index){
                    data.isSel=false;
                });
            }else if(id==3){
                $scope.fzbJson.originalPhoto.btnList.forEach(function(data,index){
                    data.isSel=false;
                });
            }else if(id==4){
                $scope.fzbJson.nonSelf.btnList.forEach(function(data,index){
                    data.isSel=false;
                });
            }
        }
        item.isSel=!item.isSel;
    }
    //开启开光
    $scope.openCheatSwitch=function(){
        $scope.fzbJson.cheatSwitch=!$scope.fzbJson.cheatSwitch;
        //关闭的时候在保存一遍
        if(!$scope.fzbJson.cheatSwitch){
            $scope.SavePlan();
        }
    }
    //保存
    $scope.SavePlan=function(){
       // console.log($scope.fzbJson);
       $scope.loading=true;
        var param={
            validateId:$scope.zjid,
            userId:sysUserInfo.getuserinfo().user_ID,
            configureJson:JSON.stringify($scope.fzbJson)
        };
        RS.modifyOrgConfigure(param).then(function (response) {
            $scope.loading=false;
                if (response.errorcode == "0") {// 成功       
                    Msg.success("保存成功！");
                } else{   // 获取失败 
                    Msg.error("保存失败！");
                }
            }, function errorCallback() {
                console.log("连接服务器失败！");
                $scope.loading=false;
            });
    }
    $scope.zjid="";
    //获取配置
    $scope.getConfig=function(){

        RS.getOrgConfigure({ userId: sysUserInfo.getuserinfo().user_ID }).then(function (response) {
                if (response.errorcode == "0"  && response.data != undefined && response.data != null&& response.data.configureJson.length>0) {// 成功       
                    $scope.fzbJson =JSON.parse(response.data.configureJson);
                    $scope.zjid=response.data.validateId;
                } else if(response.errorcode != "0") {   // 获取失败 
                    Msg.error("获取失败！");
                }
            }, function errorCallback() {
                console.log("连接服务器失败！");
            });
    }
     $scope.getConfig();
} ]);
/*****************************************************************个性化设置********************************************************************************/

//logo设置
baseModel.controller("logoSetController", ['$scope', 'sysUserInfo', '$state',"$document", "FileUploader", '$rootScope', "sysmanagerservice", 'Msg', '$http',"T", function ($scope, sysUserInfo, $state,$document, FileUploader,$rootScope, RS, Msg, $http, T) {
  /***************************************上传logo***************************************************/
    
     //获取  当前企业基本信息
    $scope.findOrgInfo = function () {
            RS.findOrgInfo({ orgId: sysUserInfo.getuserinfo().organization_ID }).then(function (response) {
                if (response.errorcode == "0" && response.data != null && response.data != undefined) {// 成功       
                    $scope.orginfo = response.data;
                } else {   // 获取失败 
                    Msg.error("获取失败！");
                }
            }, function errorCallback() {
                console.log("连接服务器失败！");
            });
    }
    $scope.findOrgInfo();

    $scope.index = 0;
    $scope.selectFile = function (index) {                
        $scope.index = index;
        $("#file").click();
    }
    $scope.isupobj = { "upflag": false, "isbtn": false, "datas": [] };   // 初始化    
    $scope.isupflagfun = function () {//点击查看传输列表
        $scope.isupobj.isbtn = true; // 标志按扭点击的
        $scope.isupobj.upflag = !$scope.isupobj.upflag;
        if ($scope.isupobj.upflag) {    // 向服务器拿数据 放这边会重置datas所以放初始化       
        }
    }
    /*********************************************文件上传开始**********************************************/
    var trainupfile = $scope.isupobj.datas = $scope.uploader = new FileUploader();
    trainupfile.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {     // 选择文件后失败       0
        console.info('onWhenAddingFileFailed', item, filter, options);
    };
    trainupfile.onAfterAddingFile = function (fileItem) {  // 选择文件后 （成功）   0          
        console.info('onAfterAddingFile', fileItem);
        if (trainupfile.isUploading) {
            MsgCon.alert("有文件正在上传。。");
            return;
        } else {
            var upfileparam = "?orgid=" + sysUserInfo.getuserinfo().organization_ID + "&optype=" + $scope.index;

            fileItem.url = RS.uploadLogo(upfileparam);
        }
    };
    trainupfile.onAfterAddingAll = function (addedFileItems) { // 选择文件后添加到队列   1 
        console.info('onAfterAddingAll', addedFileItems);
        if (trainupfile.isUploading) {
            Msg.warning("有文件正在上传。。");
            return;
        } else {
            $scope.isupobj.upflag = true;
            $scope.isupobj.isbtn = true;  // 初始化   
            trainupfile.uploadAll();
        }
    };
    // 开始上传
    trainupfile.onBeforeUploadItem = function (item) {    // 2 上传之前一项
        console.info('onBeforeUploadItem', item);
        item.file.pid = 0;
    };
    trainupfile.onProgressItem = function (fileItem, progress) {   // 3 上传进度
        console.info('onProgressItem', fileItem, progress);
    };
    trainupfile.onProgressAll = function (progress) {      //4 队列进度
        console.info('onProgressAll', progress);
    };
    trainupfile.onErrorItem = function (fileItem, response, status, headers) {     // 5上传失败
        console.info('onErrorItem', fileItem, response, status, headers);
    };
    trainupfile.onCancelItem = function (fileItem, response, status, headers) {    //5取消上传
        //$scope.exUserList[0].import_State = "取消";
        console.info('onCancelItem', fileItem, response, status, headers);
    };
    trainupfile.onCompleteItem = function (fileItem, response, status, headers) {  //6     单文件上传完成
        console.info('onCompleteItem', fileItem, response, status, headers);
        if (response.errorcode == "0") {
            //上传文件路径
            if ($scope.index == 1) {//logo
                $scope.orginfo.organization_mainlogo = response.data.fileurlonly;
                var imglogo=document.getElementById("orgLogo");
                imglogo.src=$scope.orginfo.organization_mainlogo;

            } else if ($scope.index == 2) {//播放logo
                $scope.orginfo.organization_playlogo = response.data.fileurlonly;
            } else if ($scope.index == 3) {//背景图
                $scope.orginfo.organization_login_background = response.data.fileurlonly;
            }
            $scope.saveOrgInfo();
            
        } else {
            Msg.error("图片上传异常！")
        }
    };
    trainupfile.onCompleteAll = function () {  // 6 单文件上传完成或者队列上传完成的时候
        console.info('onCompleteAll');
        //trainupfile.clearQueue();  // 上传完毕清除队列
    };
    /*********************************************文件上传结束**********************************************/
    //修改企业基本信息
    $scope.saveOrgInfo = function () {
        RS.updateOrgInfo($scope.orginfo).then(function (response) {
            if (response.errorcode == "0") {// 成功       
                Msg.success("修改成功");
                sysUserInfo.setorganizationinfo($scope.orginfo); //修改缓存
            } else {   // 获取失败 
                Msg.error("获取失败！");
            }
        }, function errorCallback() {
            console.log("连接服务器失败！");
            $scope.isOK = true;
        });
    }
} ]);
//菜单设置
baseModel.controller("menuSetController", ['$scope', 'sysUserInfo', '$state', '$rootScope', "sysmanagerservice", 'Msg', "T", function ($scope, sysUserInfo, $state, $rootScope,RS,Msg, T) {
 /*********************************学员端菜单设置*******************************/
     //获取  当前企业基本信息
    $scope.findOrgInfo = function () {
            RS.findOrgInfo({ orgId: sysUserInfo.getuserinfo().organization_ID }).then(function (response) {
                if (response.errorcode == "0" && response.data != null && response.data != undefined) {// 成功       
                    $scope.orginfo = response.data;
                    $scope.stuMenuInit();
                } else {   // 获取失败 
                    Msg.error("获取失败！");
                }
            }, function errorCallback() {
                console.log("连接服务器失败！");
            });
    }
    $scope.findOrgInfo();
    // 菜单初始化
    $scope.stuMenuInit = function(){
        $scope.stuMenuList = angular.copy( sysUserInfo.getStuMenuList());
         var oldList =[];
        if($scope.orginfo.orgContent){
            var oldList =  JSON.parse($scope.orginfo.orgContent);
        }        
        angular.forEach(oldList,function(oitem,index){
            angular.forEach($scope.stuMenuList,function(fitem,index){
                if(fitem.id == oitem.id){
                    fitem.isSel = true;
                    fitem.cnname = oitem.cnname;
                    fitem.enname = oitem.enname;
                    angular.forEach(oitem.children,function(cmenu,index){
                        angular.forEach(fitem.children,function(citem,index){
                            if(citem.id == cmenu.id){
                                citem.isSel = true;
                                citem.cnname = cmenu.cnname;
                                citem.enname = cmenu.enname;
                            }
                        });
                    })                    
                }                
            });
        })        
    }        
    $scope.delMenu = function(list,item){
        angular.forEach(list,function(menu,index){
            if(menu.id == item.id){
                list.splice(index,1);
            }else{
                 angular.forEach(menu.children,function(citem,cindex){
                        if(citem.id == item.id){
                            menu.children.splice(cindex,1);
                        }
                  });
            }
        });
        return list;
    }
    // 保存菜单
    $scope.saveMenu = function(){
        var saveMenuList = angular.copy($scope.stuMenuList);
        var MenuList =angular.copy($scope.stuMenuList);
        angular.forEach(saveMenuList,function(fitem,index){
            if(fitem.isSel){
                angular.forEach(fitem.children,function(citem,index){
                    if(!citem.isSel){
                        MenuList = $scope.delMenu(MenuList,citem);                                
                    }
                });
            }else{
                MenuList = $scope.delMenu(MenuList,fitem);
            }                             
        });
        if(MenuList.length <= 0){
            Msg.info('提示','请选择菜单！');
            return;
        }        
        $scope.orginfo.orgContent = JSON.stringify(MenuList);        
        $scope.saveOrgInfo();
    }
    $scope.checkMenu = function(menu,fmenu,level){
        // 选择的是第一级
        if(level == 1){
            if(fmenu.isSel){
                fmenu.isSel = false;                                
            }else{
                fmenu.isSel = true;
            }
            if(fmenu.children){
                angular.forEach(fmenu.children,function(item,index){
                        item.isSel = fmenu.isSel;                    
                });
            }            
        }else if(level == 2){
            if(menu.isSel){
               menu.isSel = false; 
            }else{
                menu.isSel = true;
            }            
            if(fmenu.children && menu.isSel){
               fmenu.isSel = true; 
            }            
        }
    }
   //修改企业基本信息
    $scope.saveOrgInfo = function () {
        RS.updateOrgInfo($scope.orginfo).then(function (response) {
            if (response.errorcode == "0") {// 成功       
                Msg.success("修改成功");
                sysUserInfo.setorganizationinfo($scope.orginfo); //修改缓存
            } else {   // 获取失败 
                Msg.error("获取失败！");
            }
        }, function errorCallback() {
            console.log("连接服务器失败！");
            $scope.isOK = true;
        });
    }

} ]);

/*****************************************************************其他设置********************************************************************************/

//学习设置
baseModel.controller("studySetController", ['$scope', 'sysUserInfo', '$stateParams', '$state', 'Msg', '$rootScope', "sysmanagerservice", "T", function ($scope, sysUserInfo, $stateParams, $state,Msg,$rootScope, RS,T) {
    
     // 请求参数 查询
    $scope.params = {
        orgid: sysUserInfo.getuserinfo().organization_ID,
        groupname:$rootScope.groupName,
        pageIndex:1,
        pageSize:100,
    };
    // 查询企业开关信息
    $scope.getCommonSet = function () {
        RS.findOrgSwitch($scope.params).then(function (response) {
            if (response.errorcode == "0") {
                $scope.commonlist=response.datas;
            } else if (response.errorcode == "40") {
                console.log("没有任何配置信息");
            } else {
                Msg.error("服务器异常");
            }
        });
    }
    $scope.getCommonSet();
    //打开或关闭开关
    $scope.updateState=function(item){
        RS.addOneSwitch({orgid:sysUserInfo.getuserinfo().organization_ID,orgname:sysUserInfo.getuserinfo().organization_Name,userid:sysUserInfo.getuserinfo().user_ID,username:sysUserInfo.getuserinfo().organization_Name,switchKey:item.switch_id}).then(function (response) {
                if (response.errorcode == "0") {
                    if(item.switchOrganization==undefined||item.switchOrganization==null||item.switchOrganization.is_switch!="0"){
                        item.switchOrganization={is_switch:"0"};
                    }else{
                        item.switchOrganization=null;
                    }
                    Msg.success("修改成功！");
                } else if (response.errorcode == "40") {
                    console.log("没有任何配置信息");
                } else {
                    Msg.error("错误！");
                }
            });
    }


} ]);
